package com.rockcent;

import com.rockcent.third.Config;
import com.rockcent.third.Prop;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration;
import org.springframework.context.ApplicationContext;

/**
 * Created by oyhk on 16/7/11.
 */
@SpringBootApplication
@EnableAutoConfiguration(exclude = {FreeMarkerAutoConfiguration.class, WebSocketAutoConfiguration.class, GsonAutoConfiguration.class, JmxAutoConfiguration.class})
public class BootstrapThirdApi {

    public static void main(String[] args) throws Exception {
        SpringApplication app = new SpringApplication(BootstrapThirdApi.class);
        app.setBannerMode(Banner.Mode.LOG);
        ApplicationContext applicationContext = app.run(args);

        Prop prop = (Prop) applicationContext.getBean("prop");

        // 是否生产环境
        if (applicationContext.getEnvironment().getActiveProfiles() != null && applicationContext.getEnvironment().getActiveProfiles().length > 0) {
            if (applicationContext.getEnvironment().getActiveProfiles()[0].contains(Config.PROD)) {
                prop.env = Config.PROD;
            } else if (applicationContext.getEnvironment().getActiveProfiles()[0].contains(Config.UAT)) {
                prop.env = Config.UAT;
            } else if (applicationContext.getEnvironment().getActiveProfiles()[0].contains(Config.DEV)) {
                prop.env = Config.DEV;
            } else {
                prop.env = Config.LOCAL;
            }
        }
    }

}
